home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr15 / hermite.zip / MOTION.BAS next >
BASIC Source File  |  1993-04-30  |  3KB  |  86 lines

  1. DECLARE FUNCTION NextFile$ (n!, root$, ext$)
  2. DECLARE FUNCTION CubicBlend! (t!, N1!, N2!, P1!, P2!)
  3. DECLARE FUNCTION HermiteBlend! (t!, N1!, N2!, P1!, P2!)
  4. DECLARE FUNCTION LinearBlend! (t!, N1!, N2!)
  5. DECLARE FUNCTION QuadraticBlend! (t!, N1!, N2!, P1!)
  6. '
  7. ' Demonstrates the use of Hermite blending function for camera control
  8. ' Notice the smooth speedup and slowdown.
  9. ' Dan Farmer  April '93
  10. '
  11. CLS
  12.  
  13. OPEN "motion.bat" FOR OUTPUT AS #1
  14. 'OPEN "CONS:" FOR OUTPUT AS #1
  15.  
  16.  
  17. float$="#####.#####"
  18.  
  19. ' Name of animation files goes here:
  20. root$ = "motion"
  21. incfile$ = root$ + ".inc"
  22.  
  23. ' Modify these to suit your system
  24. render$ = "\povray\povray.exe \povray\povray.def -w160 -h100 -p -i" + root$ + ".pov -o"
  25. dta$="call dta.bat " + root$
  26. play$="play " + root$ + ".fli" 
  27.  
  28. ' Start and end values for camera location vector
  29. xfrom=30 : xto=0
  30. yfrom=30 : yto=1
  31. zfrom=-50 : zto=-4
  32.  
  33.  
  34. frames = 300
  35.  
  36.  
  37. PRINT #1, "@echo off"
  38. FOR frame = 1 TO frames
  39.  
  40.     ' Number the output file
  41.     tgafile$ = NextFile$(frame, root$, ".tga")
  42.  
  43.     t = frame / frames
  44.     x = HermiteBlend(t, xfrom, xto, 0, 0)    ' Last two params are controlling
  45.     y = HermiteBlend(t, yfrom, yto, 3, 4)    ' values for the start and ending
  46.     z = HermiteBlend(t, zfrom, zto, 0, -30)  ' slopes of the curve.
  47.  
  48.     PRINT #1, "echo #declare XLoc = ";
  49.     PRINT #1, USING float$+" > " + incfile$; x
  50.     PRINT #1, "echo #declare YLoc = ";
  51.     PRINT #1, USING float$+" > " + incfile$; y
  52.     PRINT #1, "echo #declare ZLoc = ";
  53.     PRINT #1, USING float$+" > " + incfile$; z
  54.     PRINT #1, render$ + tgafile$
  55.     PRINT #1, "if errorlevel 1 exit"      ' NOTE: This may fail w/ some versions
  56.     PRINT #1, ""
  57. NEXT frame
  58. PRINT #1, dta$
  59. PRINT #1, play$"play motion.fli"
  60. END
  61.  
  62.  
  63. FUNCTION CubicBlend (t, N1, N2, P1, P2) STATIC
  64.     CubicBlend = (1 - t) ^ 3 * N1 + (t ^ 3) * N2 + 3 * t * ((1 - t) ^ 2) * P1 + 3 * (t ^ 2) * (1 - t) * P2
  65. END FUNCTION
  66.  
  67. FUNCTION HermiteBlend (t, N1, N2, P1, P2)
  68.     HermiteBlend = (N1 * ((2! * t - 3!) * t ^ 2 + 1!) + N2 * (-2! * t + 3!) * t ^ 2 + P1 * ((t - 2!) * t + 1!) * t + P2 * (t - 1!) * t ^ 2)
  69. END FUNCTION
  70.  
  71. FUNCTION LinearBlend (t, N1, N2) STATIC
  72.     LinearBlend = (1 - t) * N1 + t * N2
  73. END FUNCTION
  74.  
  75. FUNCTION NextFile$ (n, root$, ext$) STATIC
  76. STATIC i, pad$
  77.     i = 8 - LEN(root$)
  78.     pad$ = STRING$(8, "0")
  79.     NextFile$ = root$ + RIGHT$(pad$ + LTRIM$(STR$(n)), i) + ext$
  80. END FUNCTION
  81.  
  82. FUNCTION QuadraticBlend (t, N1, N2, P1) STATIC
  83.     QuadraticBlend = (1 - t) ^ 2 * N1 + (t ^ 2) * N2 + 2 * t * (1 - t) * P1
  84. END FUNCTION
  85.  
  86.